
package com.wwy.monitor.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author tianquan.ld
 * @version V1.0
 * <p>Description: æ ¼å¼校验å·¥å·</p>
 * @date 2019-11-01 16:15
 */
public class FormatUtil {
    private final static Logger logger = LoggerFactory.getLogger(FormatUtil.class);

    /**
     * 校验è¯·æ±æ¹æ³æ¯å¦æ­£ç¡®,å¿½ç¥å¤§å°å
     *
     * @param requestMethod
     * @return
     */
    public static boolean validateHttpMethod(String requestMethod) {
        if (StringUtils.isBlank(requestMethod)) {
            return false;
        }
        for (RequestMethod item : RequestMethod.values()) {
            if (item.name().equalsIgnoreCase(requestMethod)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 校验æ¯å¦ä¸ºjsonå­ç¬¦ä¸²
     *
     * @param json
     * @return
     */
    public static boolean validateJson(String json) {
        try {
            JSONObject jsonObject = JSON.parseObject(json);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return false;
        }
    }
}